package com.inda.lemurshooter;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

public class SettingsActivity extends Activity {
	
	private RadioButton explosionsOn;
	private RadioButton explosionsOff;
	private RadioButton soundOn;
	private RadioButton soundOff;
	
	private SharedPreferences settings;
	private final String SETTINGS_DATABASE="settings";
	private Editor editor;
	
	//Booleans controlling current settings
	private boolean hasExplosions=true;
	private boolean hasSound=true;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings_layout);
		
		settings= getSharedPreferences(SETTINGS_DATABASE, Context.MODE_PRIVATE);
		hasSound = settings.getBoolean("sounds", true);
		hasExplosions = settings.getBoolean("explosions", true);

				
		explosionsOn = (RadioButton)findViewById(R.id.radioButton1);
		explosionsOff = (RadioButton)findViewById(R.id.radioButton2);
		soundOn = (RadioButton)findViewById(R.id.radioButton3);
		soundOff = (RadioButton)findViewById(R.id.radioButton4);
		
		if(hasSound){
			soundOn.setChecked(true);
			soundOff.setChecked(false);
		}
		else{
			soundOn.setChecked(false);
			soundOff.setChecked(true);
		}
		
		if(hasExplosions){
			explosionsOn.setChecked(true);
			explosionsOff.setChecked(false);
		}
		else{
			explosionsOn.setChecked(false);
			explosionsOff.setChecked(true);
		}
			

	}	
	//if buttons are touched
		public void explosionsOn (View v){
			explosionsOff.setChecked(false);
			hasExplosions=true;
		}
		public void explosionsOff (View v){
			explosionsOn.setChecked(false);	
			hasExplosions=false;
		}
		public void soundOn (View v){
			soundOff.setChecked(false);
			hasSound=true;
		}
		public void soundOff (View v){
			soundOn.setChecked(false);
			hasSound=false;
		}
		public void okPushed (View v){
			finish();
		}
		
		@Override
		protected void onStop() {
			super.onStop();
			settings= getSharedPreferences(SETTINGS_DATABASE, Context.MODE_PRIVATE);
			
			editor = settings.edit();
			
			editor.putBoolean("sounds", hasSound);
			editor.putBoolean("explosions", hasExplosions);			
			
			editor.commit();
		
		}
	
	

}